<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %>--%>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="author" content="">

    <link rel="stylesheet" href="${APP_PATH}/bootstrap/css/bootstrap.min.css">
    <link rel="stylesheet" href="${APP_PATH}/css/font-awesome.min.css">
    <link rel="stylesheet" href="${APP_PATH}/css/main.css">
    <link rel="stylesheet" href="${APP_PATH}/jquery/pagination.css">
    <style>
        .tree li {
            list-style-type: none;
            cursor:pointer;
        }
        table tbody tr:nth-child(odd){background:#F4F4F4;}
        table tbody td:nth-child(even){color:#C00;}
    </style>
</head>

<body>

<nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
    <div class="container-fluid">
        <div class="navbar-header">
            <div><a class="navbar-brand" style="font-size:32px;" href="#">众筹平台 - 流程管理</a></div>
        </div>
        <div id="navbar" class="navbar-collapse collapse">
            <ul class="nav navbar-nav navbar-right">
                <%@ include file="/WEB-INF/jsp/common/top.jsp"%>
            </ul>
            <form class="navbar-form navbar-right">
                <input type="text" class="form-control" placeholder="Search...">
            </form>
        </div>
    </div>
</nav>

<div class="container-fluid">
    <div class="row">
        <div class="col-sm-3 col-md-2 sidebar">
            <jsp:include page="/WEB-INF/jsp/common/menu.jsp"></jsp:include>
        </div>
        <div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">
            <div class="panel panel-default">
                <div class="panel-heading">
                    <h3 class="panel-title"><i class="glyphicon glyphicon-th"></i> 数据列表</h3>
                </div>
                <div class="panel-body">
                    <form class="form-inline" role="form" style="float:left;">
                        <div class="form-group has-feedback">
                            <div class="input-group">
                                <div class="input-group-addon">查询条件</div>
                                <input class="form-control has-success" type="text" placeholder="请输入查询条件">
                            </div>
                        </div>
                        <button type="button" class="btn btn-warning"><i class="glyphicon glyphicon-search"></i> 查询</button>
                    </form>

                    <button type="button" id="uploadPrcDefBtn" class="btn btn-primary" style="float:right;"><i class="glyphicon glyphicon-upload"></i> 上传流程定义文件</button>
                    <br>
                    <hr style="clear:both;">
                    <div class="table-responsive">

                        <form id="uploadForm" action="" method="POST" enctype="multipart/form-data">
                            <input id="processDefFile" type="file" name="processDefFile" style="display: none">
                        </form>

                        <table class="table  table-bordered">
                            <thead>
                            <tr >
                                <th width="30">#</th>
                                <th>流程定义名称</th>
                                <th>流程定义版本</th>
                                <th>流程定义的Key</th>
                                <th width="100">操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            <tr>
                                <td>1</td>
                                <td>实名认证审批流程</td>
                                <td>2</td>
                                <td>人工审核</td>
                                <td>张三</td>
                                <td>
                                    <button type="button" class="btn btn-success btn-xs"><i class=" glyphicon glyphicon-eye-open"></i></button>
                                    <button type="button" class="btn btn-danger btn-xs"><i class=" glyphicon glyphicon-remove"></i></button>
                                </td>
                            </tr>
                            </tbody>
                            <tfoot>
                            <tr >
                                <td colspan="6" align="center">
                                    <div id="Pagination" class="pagination">
                                        <%--  这里显示分页  --%>
                                    </div>
                                </td>
                            </tr>

                            </tfoot>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<script src="${APP_PATH}/jquery/jquery-2.1.1.min.js"></script>
<script src="${APP_PATH}/bootstrap/js/bootstrap.min.js"></script>
<script src="${APP_PATH}/script/docs.min.js"></script>
<script src="${APP_PATH}/jquery/jquery.pagination.js"></script>
<script type="text/javascript" src="${APP_PATH }/jquery/layer/layer.js"></script>
<script src="${APP_PATH }/jquery/jquery-form/jquery-form.min.js"></script>
<script type="text/javascript">
    $(function () {
        $(".list-group-item").click(function(){
            if ( $(this).find("ul") ) {
                $(this).toggleClass("tree-closed");
                if ( $(this).hasClass("tree-closed") ) {
                    $("ul", this).hide("fast");
                } else {
                    $("ul", this).show("fast");
                }
            }
        });
        showMenu()
        queryProcess(0)
    });

    var loadingIndex = -1

    var jsonObj = {
        "pageNo": 1,
        "pageSize": 10
    }

    function queryProcess(pageIndex){
        var tbody = $("tbody")
        tbody.empty()
        jsonObj.pageNo = pageIndex + 1;
        $.ajax({
            type: 'POST',
            data: jsonObj,
            url: "${APP_PATH}/process/doIndex.do",
            beforeSend: function(){
                loadingIndex = layer.load(2,{time: 10*1000})
                return true;
            },
            success: function(result){

                layer.close(loadingIndex)

                if(result.success){
                    var page = result.page;
                    var data = page.datas;

                    $.each(data,function(index,value){
                        var content = ''
                        content += '<tr>';
                        content += '	<td>'+(index + 1)+'</td>';
                        content += '	<td>'+value.name+'</td>';
                        content += '	<td>'+ value.version +'</td>';
                        content += '	<td>'+ value.key +'</td>';
                        content += '	<td>';
                        content += '		<button type="button" class="btn btn-success btn-xs" onclick="showimg(\''+value.id+'\')"><i class=" glyphicon glyphicon-eye-open"></i></button>';
                        content += '		<button type="button" onclick="deleteProDef(\''+value.id+'\',\''+value.name+'\')" class="btn btn-danger btn-xs"><i class=" glyphicon glyphicon-remove"></i></button>';
                        content += '	</td>';
                        content += '</tr>';
                        tbody.append(content)
                    });

                    var num_entries = page.totalsize ;
                    $("#Pagination").pagination(num_entries, {
                        num_edge_entries: 2, //边缘页数
                        num_display_entries: 4, //主体页数
                        callback: queryProcess, //查询当前页的数据.
                        items_per_page:page.pagesize, //每页显示1项
                        current_page:(page.pageno-1), //当前页,索引从0开始
                        prev_text:"上一页",
                        next_text:"下一页"
                    });


                }else{
                    layer.msg(result.message,{time: 1000,icon: 5,shift:6})
                }
            },
            error: function(result){
                layer.msg(result.message,{time: 1000,icon: 5,shift:6})
            }
        })
    }

    $("#uploadPrcDefBtn").click(function(){
        $("#processDefFile").click()
    })

    $("#processDefFile").change(function(){
        var options = {
            url: "${APP_PATH}/process/deploy.do",
            beforeSend: function () {
                loadingIndex = layer.msg("数据正在部署中",{icon: 6})
                return true
            },
            success: function (result) {
                layer.close(loadingIndex)
                if(result.success){
                    layer.msg(result.message,{time: 1000,icon: 6})
                    queryProcess(0)
                }else{
                    layer.msg(result.message,{time:1000,icon:5,shift:6})
                }
            }
        }

        $("#uploadForm").ajaxSubmit(options);//异步提交
    })

    function deleteProDef(id,name){
        layer.confirm("您确定要删除"+name+"流程定义吗",{icon: 3,title: '提示'},function(cindex){
            $.ajax({
                type: "POST",
                url: '${APP_PATH}/process/doDeleteAll.do',
                data: {
                    id
                },
                beforeSend: function(){
                    return true
                },
                success: function(result){
                    if(result.success){
                        queryProcess(0)
                    }else{
                        layer.msg(result.message,{time: 1000,icon: 5,shift: 6})
                    }
                },
                error: function(result){
                    layer.msg(result.message,{time: 1000,icon: 5,shift: 6})
                }
            })
            layer.close(cindex)
        },function(cindex){
            //取消删除
            layer.close(cindex)
        })
    }

    function showimg(id){
        window.location.href = "${APP_PATH}/process/showimg.do?id="+id;
    }

</script>
<script type="text/javascript" src="${APP_PATH}/script/menu.js"></script>
</body>
</html>
